package com.software.demo3.test;

import com.software.demo3.entity.HourlyEmployee;
import com.software.demo3.entity.SalaryEmployee;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class Run {
    public static void main(String[] args) {
        Configuration cfg = new Configuration();
        cfg.configure();

        SessionFactory sessionFactory = cfg.buildSessionFactory();
        Session session = sessionFactory.openSession();

        Transaction transaction = session.beginTransaction();
        //业务逻辑
        HourlyEmployee hourlyEmployee = new HourlyEmployee();
        hourlyEmployee.setName("demo3-hourly");
        hourlyEmployee.setRate(150.0);
        session.save(hourlyEmployee);

        SalaryEmployee salaryEmployee = new SalaryEmployee();
        salaryEmployee.setName("demo3-salary");
        salaryEmployee.setSalary(20000.0);
        session.save(salaryEmployee);

        transaction.commit();
        session.close();
        sessionFactory.close();
    }
}
